/*
 * ColorChooserDelegate  0.4.0 / Dec 04, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
#include "ColorChooserDelegate.h"

#include "ComponentDelegate.h"

// ColorChooserDelegate :: Static Native Calls. --------------------------------

/*!
 * \brief Returns color selected by the user.
 *
 * \param env the JNIEnv pointer
 * \param cls the ColorChooser java class
 * \param parentDelegate the parent delegate
 * \param initialColor the initial color
 * 
 * \return color selected by the user
 */
jobject ColorChooserDelegate::getColor(JNIEnv *env, jclass cls,
                                       jlong parentDelegate, jint initialColor)
{
  Q_ASSERT(env);
  SWING_STATIC_REENTRANT_RETURN(ColorChooserDelegate, getColor, jobject,
                                SWING_ENV_ARG, JCLASS_ARG(cls),
                                JLONG_ARG(parentDelegate),
                                JINT_ARG(initialColor))
  QWidget *parent = 0;
  if (parentDelegate) {
    parent = COMPONENT_CAST(parentDelegate)->qWidget();
  }
  QColor selectedColor = QColorDialog::getColor(QColorAdapter(initialColor),
                                                parent);
  if (selectedColor.isValid()) {
    return QColorAdapter::toJColor(selectedColor);
  }
  return 0;
}
